import { useUserStore } from "@/store";

/*
 * @Author: anxia.ack anchenkai@come-future.com
 * @Date: 2025-04-20 19:32:15
 * @LastEditors: anxia.ack anchenkai@come-future.com
 * @LastEditTime: 2025-04-21 10:50:13
 * @FilePath: /free-learning/src/utils/tourConfig.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export interface TourConfigValueType {
  isFirstLogin: boolean;
  isFirstInCourse: boolean;
  isFirstInMessage: boolean;
  isFirstInCourseChapters: boolean;
}

const userStore = useUserStore();
const tourConfig = {
  getTourConfig: (key: keyof TourConfigValueType): boolean => {
    if (userStore.userInfo.roles.includes("ROOT") || userStore.userInfo.roles.includes("ADMIN")) {
      return false;
    }
    if (!localStorage.getItem("tourConfig")) {
      return true;
    }
    return JSON.parse(localStorage.getItem("tourConfig") || "{}")[key];
  },
  getAllTourConfig: (): TourConfigValueType => {
    return JSON.parse(localStorage.getItem("tourConfig") || "{}");
  },
  setTourConfig: (key: keyof TourConfigValueType, value: boolean) => {
    const tourConfigValue = tourConfig.getAllTourConfig();
    tourConfigValue[key] = value;
    localStorage.setItem("tourConfig", JSON.stringify(tourConfigValue));
  },
  clearTourConfig: () => {
    localStorage.removeItem("tourConfig");
  },
};
export default tourConfig;
